package com.wen.mall.product.web;

import com.wen.mall.product.entity.CategoryEntity;
import com.wen.mall.product.service.CategoryService;
import com.wen.mall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author 为`QWQ`
 * @date 2022/9/18
 * @description: TODO
 **/
@Controller
public class IndexController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/", "/index"})
    public String indexPage(Model model){
        // ToDo 1.查出所有分类
        List<CategoryEntity> categoryEntities = categoryService.getLevel1Categorys();
        model.addAttribute("categories",categoryEntities);
        return "index";
    }

    /**
    * @Description: index/json/catalog.json
    * @Param: []
    * @return: java.util.Map<java.lang.String,java.util.List<com.wen.mall.product.vo.Catelog2Vo>>
    * @Author: S.W.L
    * @Date: 2022/9/18
    * @Time: 16:02
    */
    @GetMapping(value = "/index/catalog.json")
    @ResponseBody
    public Map<String, List<Catelog2Vo>> getCatalogJson() {

        Map<String, List<Catelog2Vo>> catalogJson = categoryService.getCatalogJson();

        return catalogJson;

    }

}
